﻿using AutoMapper;
using ProjectManageSystemApi.DbEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Threading.Tasks;

namespace ProjectManageSystemApi.Services.Impl
{
    public class CostApplyImageServices : ICostApplyImageServices
    {
        readonly IFreeSql _fsql;
        readonly IMapper _mapper;
        public CostApplyImageServices(IFreeSql fsql, IMapper mapper) 
        {
            _fsql = fsql;
            _mapper = mapper;
        }
        public bool Insert(int costId, List<string> images, long creater) 
        {
            var datas = images.Select(x => new CostImageInfo
            {
                CostId = costId,
                ImageUrl = x,
                CreateTime = DateTime.Now,
                CreateUser = creater
            });
            var r = _fsql.Insert<CostImageInfo>(datas).ExecuteAffrows();
            if (r < images.Count) 
            {
                return false;
            }
            return true;
        }
        public bool Delete(int costId) 
        {
            return _fsql.Delete<CostImageInfo>().Where(x => x.CostId == costId).ExecuteAffrows() > 0;
        }
    }
}
